package cheme.ProcessEditor;

import org.eclipse.gef.palette.CombinedTemplateCreationEntry;
import org.eclipse.gef.palette.PaletteDrawer;
import org.eclipse.gef.palette.PaletteGroup;
import org.eclipse.gef.palette.PaletteRoot;
import org.eclipse.gef.palette.ToolEntry;
import org.eclipse.gef.requests.CreationFactory;
import org.eclipse.gef.requests.SimpleFactory;

import cheme.ProcessEditor.Tools.ChemeSelectionToolEntry;
import cheme.ProcessEditor.Tools.CreateGroupToolEntry;
import cheme.ProcessEditor.Tools.StreamCreationToolEntry;
import cheme.ProcessModel.ProcessModelConstants;
import cheme.ProcessModel.Interpreter.ModelFactory;
import cheme.ProcessModel.ProcessUnits.Mixer;
import cheme.ProcessModel.ProcessUnits.Separator;
import cheme.ProcessModel.ProcessUnits.SplitJoin;
import cheme.ProcessModel.ProcessUnits.Streams.Stream;
import cheme.ProcessModel.Subprocess.Subprocess;

public class PaletteViewerCreator
{
	/** the palette root */
	private PaletteRoot paletteRoot;

	/**
	 * Returns the <code>PaletteRoot</code> this editor's palette uses.
	 * 
	 * @return the <code>PaletteRoot</code>
	 */
	public PaletteRoot createPaletteRoot()
	{
		PaletteRoot root = new PaletteRoot();

		PaletteGroup toolGroup = new PaletteGroup(
				ChemeConstants.PALETTE_MAIN_GROUP_LABEL);

		//----------------------------------------------------------------------

		ToolEntry toolEntry = new ChemeSelectionToolEntry();

		toolGroup.add(toolEntry);
		root.setDefaultEntry(toolEntry);

		root.add(toolGroup);

		PaletteDrawer drawer = new PaletteDrawer(
				ChemeConstants.PALETTE_PROCESS_UNIT_GROUP_LABEL);

		//----------------------------------------------------------------------
		toolEntry = new CombinedTemplateCreationEntry(
				ChemeConstants.PALETTE_ITEM_MIXER_LABEL,
				ChemeConstants.PALETTE_ITEM_MIXER_DESC, Mixer.class,
				new SimpleFactory(Mixer.class), ChemeConstants.DESC_MIXER,
				ChemeConstants.DESC_MIXER);
		drawer.add(toolEntry);

		toolEntry = new CombinedTemplateCreationEntry(
				ChemeConstants.PALETTE_ITEM_SEPARATOR_LABEL,
				ChemeConstants.PALETTE_ITEM_SEPARATOR_DESC, Separator.class,
				new SimpleFactory(Separator.class),
				ChemeConstants.DESC_SEPARATOR, ChemeConstants.DESC_SEPARATOR);
		drawer.add(toolEntry);

		/*toolEntry = new CombinedTemplateCreationEntry(
				ChemeConstants.PALETTE_ITEM_SPLIT_JOIN_LABEL,
				ChemeConstants.PALETTE_ITEM_SPLIT_JOIN_DESC, SplitJoin.class,
				new SimpleFactory(SplitJoin.class),
				ChemeConstants.DESC_SPLIT_JOIN, ChemeConstants.DESC_SPLIT_JOIN);
		drawer.add(toolEntry);*/

		root.add(drawer);

		//----------------------------------------------------------------------
		drawer = new PaletteDrawer(
				ChemeConstants.PALETTE_SUBPROCESS_GROUP_LABEL);

		/*toolEntry = new CreateGroupToolEntry(
				ChemeConstants.PALETTE_ITEM_SUBPROCESS_LABEL,
				ChemeConstants.PALETTE_ITEM_SUBPROCESS_DESC, new SimpleFactory(
						Subprocess.class));
		drawer.add(toolEntry);

		root.add(drawer);*/

		//----------------------------------------------------------------------
		drawer = new PaletteDrawer(
				ChemeConstants.PALETTE_CHEMICAL_STREAM_GROUP_LABEL);

		StreamCreationToolEntry arrowConnxCreationEntry = new StreamCreationToolEntry(
				ChemeConstants.PALETTE_ITEM_CHEMICAL_STREAM_LABEL,
				ChemeConstants.PALETTE_ITEM_CHEMICAL_STREAM_DESC,
				new CreationFactory()
				{
					public Object getNewObject()
					{
						return ModelFactory.createModelElement(
								ProcessModelConstants.STREAM, null);
					}

					public Object getObjectType()
					{
						return Stream.class;
					}
				}, ChemeConstants.DESC_STREAM, ChemeConstants.DESC_STREAM);
		drawer.add(arrowConnxCreationEntry);

		root.add(drawer);

		//----------------------------------------------------------------------

		return root;
	}

	/**
	 * @return Returns the paletteRoot.
	 */
	public PaletteRoot getPaletteRoot()
	{
		return paletteRoot;
	}
}